package com.tbit.uqbike.webmanager.controller;


import com.tbit.common.constant.CommonConstant;
import com.tbit.uqbike.constant.Constants;
import com.tbit.uqbike.object.pojo.QuickReply;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.QuickReplyService;
import com.tbit.uqbike.webmanager.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


import java.util.Objects;

/**
 * 快捷回复表(QuickReply)表控制层
 *
 * @author shanyong.mo
 * @since 2025-02-11 10:09:05
 */
@RestController
@RequestMapping("/quickReply")
public class QuickReplyController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private QuickReplyService quickReplyService;

    /**
     * 分页查询
     * @param pageNum 页码
     * @param pageSize 页长
     * @param search 搜索内容
     * @return 查询结果
     */
    @GetMapping("/queryByPage")
    public JsonResult queryByPage( Integer pageNum, Integer pageSize, String search, HttpServletRequest request) {
        QuickReply quickReply = new QuickReply();
        LoginInfo login = getLogin(request);
        quickReply.setAccountId(login.getId());
        quickReply.setUserId(login.getAccountUserId());
        quickReply.setPlatform(CommonConstant.QUICK_REPLY_PLATFORM_MANAGER_OR_MAIN);
        return JsonResult.ok(this.quickReplyService.queryByPage(quickReply, pageNum, pageSize, search),quickReplyService.queryCount(quickReply,search));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public JsonResult queryById(@PathVariable("id") Integer id) {
        return JsonResult.ok(this.quickReplyService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param quickReply 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public JsonResult add(QuickReply quickReply,HttpServletRequest request) {
//        Assert.notNull(quickReply.getPlatform(),"找不到用户所属平台");
        Assert.notNullCheckLength(quickReply.getQuickReply(),CommonConstant.QUICK_REPLY_MAX_LENGTH,"快捷回复内容为空或超过指定长度200字符");
        LoginInfo login = getLogin(request);
        quickReply.setAccountId(login.getId());
        quickReply.setUserId(login.getAccountUserId());
        quickReply.setPlatform(CommonConstant.QUICK_REPLY_PLATFORM_MANAGER_OR_MAIN);
        return JsonResult.ok(this.quickReplyService.insertCheckNull(quickReply));
    }

    /**
     * 编辑数据
     *
     * @param quickReply 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public JsonResult edit(QuickReply quickReply) {
        Assert.notNullCheckLength(quickReply.getQuickReply(),CommonConstant.QUICK_REPLY_MAX_LENGTH,"快捷回复内容为空或超过指定长度200字符");
        Assert.notNull(quickReply.getId(),"找不到修改主键");
        return JsonResult.ok(this.quickReplyService.updateCheckNull(quickReply));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/delete")
    public JsonResult deleteById(Integer id) {
        return JsonResult.ok(this.quickReplyService.deleteById(id));
    }

}

